/**
 *  1_100 表示金币100
    2_200 表示钻石200
    3_10  表示累计玩10关
    4_3   表示连续登陆3天
    6_8  表示累计分享好友8次
    7_10  表示累计看视频10次
    8_1  表示累计登陆1天
    9_1  表示普通刀具收集完成
    9_2  表示特殊刀具收集弯成
    10_水果id_数量 
    11_20 表示一刀切20次
    12_60 表示转60次幸运转盘
    13_5 表示看5次视频
 */
class ConditionUtil {
    private static _instance:ConditionUtil;

    public static instance(){
        if(!this._instance)
        {
            this._instance = new ConditionUtil();
        }
        return this._instance;
    }

    public parseConditon(condition:string):ConditionData
    {
        let conditionArr = condition.split('_');
        let data = {
            icon:"",
            num:"",
            desc:"",
            type:0
        }
        let con = parseInt(conditionArr[0]);
        data.type = con;
        switch(con)
        {
            case conditionType.gold:
                data.icon = 'icon_gold';
                data.num = conditionArr[1];
            break;
            case conditionType.diamond:
                data.icon = 'icon_diamond';
                data.num = conditionArr[1];
            break;
            case conditionType.cut_fruit:
                data.num = conditionArr[2];
            break;
            default:
                if(conditionType.total_customs || conditionType.total_login || conditionType.total_luck_wheel
                ||conditionType.total_share || conditionType.one_knife || conditionType.continued_login || conditionType.invite)
                data.num = conditionArr[1];
            break;
        }
        if(conditionArr.length == 2)
        {
                data.desc = StringUtil.getSwfLangStrVar('con_'+conditionArr[0], [conditionArr[1]]);
        }
        else if(conditionArr.length == 3)
        {
            //三个的
            if(con == conditionType.cut_fruit)
            {
                let fruit_id = parseInt(conditionArr[1]);
                let fruit_data = DataJson.fruit_data[fruit_id];
                let name = '';
                if(fruit_data)
                {
                    name = fruit_data.name;
                }
                else
                {
                    LogUtil.error('wrong fruit_id: '+fruit_id);
                }
                // console.log(data.num);
                
                data.desc = StringUtil.getSwfLangStrVar('con_'+conditionArr[0], [data.num, name]);
            }
            else if(con == conditionType.knife_collection)
            {
                let type = parseInt(conditionArr[1]);
                let typeDesc:string = type ==  weaponType.normal? '普通':'特殊';
                data.desc = StringUtil.getSwfLangStrVar('con_'+conditionArr[0], [typeDesc]);
            }
            data.num = conditionArr[2];
        }
        
        return data;
    }

    public judgeConditon(condition:string)
    {
        let conditionArr = condition.split('_');
        let myMoney = RoleCache.instance().myMoney;
        let myDiamond = RoleCache.instance().myDiamond;
        let num = parseInt(conditionArr[1]);
        let con = parseInt(conditionArr[0]);
        let result = 0; //1金币不足 2钻石不足 3指定条件达成 0达成
        switch(con)
        {
            case conditionType.gold:
                if(myMoney < num)
                result = 1;
                break;
            case conditionType.diamond:
                if(myDiamond < num)
                result = 2;
                break;
            default:
                result = 3;
                break;
        }
        return result;
    }
}


enum conditionType {
    default,
    gold,
    diamond,
    total_customs,
    continued_login,
    none,//没有写
    total_share,
    total_vedio,
    total_login,
    knife_collection,
    cut_fruit,
    one_knife,
    total_luck_wheel,
    invite
}

interface ConditionData{
    icon:string
    num:string
    desc:string,
    type:number
}